const { DataTypes } = require('sequelize');

module.exports = (sequelize) => {
    const ClothingCategory = sequelize.define('ClothingCategory', {
        id: {
            type: DataTypes.BIGINT,
            primaryKey: true,
            autoIncrement: true,
            comment: '分类ID'
        },
        name: {
            type: DataTypes.STRING(50),
            allowNull: false,
            comment: '分类名称'
        },
        description: DataTypes.TEXT,
        points_per_kg: {
            type: DataTypes.DECIMAL(10, 2),
            comment: '每公斤积分'
        },
        status: {
            type: DataTypes.TINYINT,
            defaultValue: 1,
            comment: '1-启用 0-禁用'
        },
        deleted_at: DataTypes.DATE
    }, {
        paranoid: true,
        underscored: true,
        timestamps: true,
        tableName: 'clothing_categories',
        comment: '衣物分类表'
    });

    ClothingCategory.associate = function (models) {
        ClothingCategory.hasMany(models.OrderItem, {
            foreignKey: 'category_id',
            as: 'order_items'
        });
    };

    return ClothingCategory;
};